package com.itheima.controller.backend.reservation;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @className CheckItemController
 */
@RestController
@RequestMapping("/checkitem")
public class CheckItemController {

    @Autowired
    private CheckItemService checkItemService;

    /**
     * 查询所有检查项
     * @return Result
     **/
    @GetMapping("/findAll")
    public Result getAllCheckItem(){
        List<CheckItem> checkItemList = checkItemService.getAllCheckItem();
        return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS, checkItemList);
    }
    /**
     * 分页查询检查项
     * @param queryPageBean 查询条件：项目编码、项目名称
     * @return PageResult
     **/
    @PostMapping("/findPage")
    public PageResult getCheckItemByPage(@RequestBody QueryPageBean queryPageBean){
        return checkItemService.getCheckItemByPage(queryPageBean);
    }

    /**
     * 添加检查项
     * @param checkItem
     * @return Result
     **/
    @PostMapping("/add")
    public Result addCheckItem(@RequestBody CheckItem checkItem){
        checkItemService.addCheckItem(checkItem);
        return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS);
    }

    /**
     * 删除检查项
     * @param id 检查项id
     * @return Result
     **/
    @GetMapping("/delete")
    public Result deleteCheckItem(Integer id) {
        checkItemService.deleteCheckItem(id);
        return new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS);
    }

    /**
     * 编辑检查项
     * @param checkItem
     * @return Result
     **/
    @PostMapping("/edit")
    public Result editCheckItem(@RequestBody CheckItem checkItem){
        checkItemService.editCheckItem(checkItem);
        return new Result(true, MessageConstant.EDIT_CHECKITEM_SUCCESS);
    }

    /**
     * 根据id查询检查项
     * @param id 检查项id
     * @return Result
     **/
    @GetMapping("/findById")
    public Result findById(Integer id){
        CheckItem checkItem = checkItemService.findById(id);
        return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS, checkItem);
    }

    /**
     * 根据检查组id查询检查项id
     * @param groupId 检查组id
     * @return Result
     **/
    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdsByCheckGroupId(@RequestParam("checkgroupId") Integer groupId){
        List<Integer> checkItemIds = checkItemService.findCheckItemIdsByCheckGroupId(groupId);
        return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS, checkItemIds);
    }
}
